package pcb.control.commands 
{
	import com.intel.patterns.cairngorm.CairngormEvent;
	import com.intel.utils.Debugger;
	import flash.display.Loader;
	import flash.net.navigateToURL;
	import flash.net.SharedObject;
	import flash.net.URLRequest;
	import pcb.control.events.InteractionEvent;
	import pcb.control.events.LoadDataEvent;
	import flash.system.System;
	
	/**
	 * ...
	 * @author Fintan Boyle
	 */
	public class Cmd_respondToUserGesture extends AbstractCommand 
	{
		
		public function Cmd_respondToUserGesture() 
		{
			
		}
		
		override public function execute(event:CairngormEvent):void 
		{
			Debugger.traceOut("Cmd_respondToUserGesture > execute()");
			
			var e:InteractionEvent = event as InteractionEvent;
			
			Debugger.traceOut("e.data >> " + e.data);
			
			switch (e.data) 
			{
				case "quit":
					models.lessonStateModel.quit();
					break;
				case "previous":
					models.lessonStateModel.prevPage();
					break;
				case "next":
					models.lessonStateModel.nextPage();
					break;
				case "previous-lesson":
					var tmp:String = models.playerStateModel.prevLessonId();
					Debugger.traceOut("lesson " + tmp);
					break;
				case "next-lesson":
					var tmp2:String = models.playerStateModel.nextLessonId();
					Debugger.traceOut("lesson " + tmp2);
					break;
				case "play":
					models.lessonStateModel.startPagePlay();
					break;
				case "pause":
					models.lessonStateModel.pausePlay();
					break;
				case "stop":
					models.lessonStateModel.currentPageIndex = -1;
					models.lessonStateModel.stopPagePlay();
					break;
				case "sound_off":
					Debugger.traceOut("sound_off ");
					//models.lessonStateModel.isMuted = true; //lesson level
					models.playerStateModel.isMuted = true; //player level
					break;
				case "sound_on":
				Debugger.traceOut("sound_on ");
					//models.lessonStateModel.isMuted = false;
					models.playerStateModel.isMuted = false;
					break;
				case "replay":
					models.lessonStateModel.currentPageIndex = -1;
					models.lessonStateModel.startPagePlay();
					break;
				case "auto-slide-transition-on":
					models.playerSettings.autoSlideTransition = true;
					break;
				case "auto-slide-transition-off":
					models.playerSettings.autoSlideTransition = false;
					break;
				case "eula-agreed-to-terms":
				
					var eulaSo:SharedObject = SharedObject.getLocal("intelEulaInfo");
					eulaSo.data.agreed = "yes";
					eulaSo.flush();
					
					var ev:LoadDataEvent = new LoadDataEvent(LoadDataEvent.RETRIEVE_LESSON_ID);
					ev.dispatch();
					
					if(models.playerSettings.useMainMenu) if(!models.playerStateModel.activated){
						var evMenu:LoadDataEvent = new LoadDataEvent(LoadDataEvent.LOAD_MAIN_MENU);
						evMenu.dispatch();
					}
					
					models.playerStateModel.activated = true;
				
					break;
				case "eula-disagreed-to-terms":
				
					var eulaNoSo:SharedObject = SharedObject.getLocal("intelEulaInfo");
					eulaNoSo.data.agreed = "no";
					eulaNoSo.flush();
					
					//quit application
					trace("models.playerSettings.deployment " + models.playerSettings.deployment);
					if(models.playerSettings.deployment != "web") {
						System.exit(0);					
					} else {					
						var url:URLRequest = new URLRequest("http://www.intel.com");
						navigateToURL(url, "_self");
					}
					break;
				case "show_legal":
					models.playerStateModel.showEula = true;
					break;
				default:
					Debugger.traceOut("Gesture not handled in Cmd_respondToUserGesture: " + e.data, Debugger.WARNING);
					break;
			}
		}
		
	}
	
}